
function handleKeydownEvent(e) {
    if (isTextfield(e))
        return;

    var code = e.keyCode;
    switch (code) {
        case 65:
            keydown("STRAFE_LEFT");
            break;
        case 87:
            keydown("MOVE_FORWARD");
            break;
        case 68:
            keydown("STRAFE_RIGHT");
            break;
        case 83:
            keydown("MOVE_BACKWARD");
            break;
        default:
    }
}

function handleKeyupEvent(e) {
    if (isTextfield(e))
        return;

    var code = e.keyCode;
    switch (code) {
        case 65:
            keyup("STRAFE_LEFT");
            break;
        case 87:
            keyup("MOVE_FORWARD");
            break;
        case 68:
            keyup("STRAFE_RIGHT");
            break;
        case 83:
            keyup("MOVE_BACKWARD");
            break;
        default:
    }
}

function isTextfield(e) {
    var tag = e.target.tagName.toLowerCase();
    return tag === 'input' || tag === 'textarea';
}